local nisi = fk.CreateSkill{
  name = "xiaobai__nisi",
  attached_kingdom = {"wei"},
  tags = {Skill.AttachedKingdom}
}

Fk:loadTranslationTable{
  ["xiaobai__nisi"] = "猊伺",
  [":xiaobai__nisi"] = "魏势力技，当你对其他角色造成或受到其他角色造成的伤害后，你可以与其同时选择一项:1.变更势力至蜀；2.摸一张牌；若你与其选择项不同，则你获得其一张牌。",
  ["nisi-draw"] = "摸一张牌",
  ["nisi-changeKingdom"] = "变更势力至蜀",
  [":nisi-changeKingdom"] = "若对方选择摸一张牌，申仪 可以获得对方一张牌。",
  [":nisi-draw"] = "若对方选择变更势力，申仪 可以获得对方一张牌。",
  ["nisi-choose"] = "猊伺：选择一项",
  ["nisi-obtainCard"] = "猊伺：获得其一张牌",

  ["$xiaobai__nisi1"] = "休执迷！皇叔破操，英雄归附，正合天意！",
  ["$xiaobai__nisi2"] = "《诗》云“自求多福”，在我而已，何求他人？",
}

local U = require "packages.utility.utility"

local spec = {
  anim_type = "defensive",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(self) and target == player and data.to ~= data.from and data.from ~= nil
  end,
  on_use = function (self, event, target, player, data)
    local players = {data.to, data.from}
    if data.to ~= player then
      players[2] = data.to
      players[1] = data.from
    end
    local room = player.room
    local choice_list = {"nisi-draw"}
    if players[2].kingdom ~= "shu"then
      choice_list = {"nisi-draw", "nisi-changeKingdom"}
    end
    local choices = U.doStrategy(room, players[1], players[2], {"nisi-draw", "nisi-changeKingdom"}, choice_list, nisi.name, 0, "nisi-choose")
    if choices[1] == "nisi-changeKingdom" then
      room:changeKingdom(players[1], "shu")
    else
      players[1]:drawCards(1, nisi.name)
    end
    if choices[2] == "nisi-changeKingdom" then
      room:changeKingdom(players[2], "shu")
    else
      players[2]:drawCards(1,nisi.name)
    end
    if choices[1] ~= choices[2] then
      if not players[2]:isNude() then
        local card = room:askToChooseCard(player, {
          target = players[2],
          flag = 'he',
          skill_name = nisi.name,
          prompt = "nisi-obtainCard"})
        room:obtainCard(player, card, false)
      end
    end
  end
}

nisi:addEffect(fk.Damage, spec)
nisi:addEffect(fk.Damaged, spec)

return nisi